<template>
  <div class="mod-crm__crmlinkrecord">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-button @click="state.getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="state.exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('crm:crmlinkrecord:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('crm:crmlinkrecord:delete')" type="danger" @click="state.deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="tskId" label="任务id" header-align="center" align="center"></el-table-column>
      <el-table-column prop="psnId" label="观众id" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskType" label="联络类型" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdGrade" label="联络评价" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdResult" label="联络结果" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdLinkState" label="联络状态" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdReason" label="联络原因" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdHistory" label="联络历史" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdPlanTime" label="计划联络时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdRecordpath" label="声音文件路径" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdTarget" label="联络目的" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdContent" label="联络内容" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdAnswer" label="回答的调查问题" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdLastLinkTime" label="最后联络时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdLastLinkStfId" label="最后联络人员id" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdTimes" label="联络次数" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdSysState" label="状态" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdIfBack" label="是否回复" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdReplyTime" label="回复时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdRemark" label="备注" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdSource" label="数据来源,如果是导入的则取临时表表名,否则是CRM的为空" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdRegcard" label="regcard" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdIfNew" label="ifNew" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdCreateTime" label="创建时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdOwnerId" label="ownerId" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdReply" label="reply" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdNextTime" label="nextTime" header-align="center" align="center"></el-table-column>
      <el-table-column prop="comId" label="公司id" header-align="center" align="center"></el-table-column>
      <el-table-column prop="exhId" label="展会id" header-align="center" align="center"></el-table-column>
      <el-table-column prop="plkId" label="plkId" header-align="center" align="center"></el-table-column>
      <el-table-column prop="actorcode" label="actorcode" header-align="center" align="center"></el-table-column>
      <el-table-column prop="oldLrdId" label="oldLrdId" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lrdUpdateTime" label="更新时间" header-align="center" align="center"></el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="state.hasPermission('crm:crmlinkrecord:update')" type="primary" link @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="state.hasPermission('crm:crmlinkrecord:delete')" type="primary" link @click="state.deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update :key="addKey" ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { nextTick, reactive, ref, toRefs, watch } from "vue";
import AddOrUpdate from "./crmlinkrecord-add-or-update.vue";

const view = reactive({
  getDataListURL: "/crm/crmlinkrecord/page",
  getDataListIsPage: true,
  exportURL: "/crm/crmlinkrecord/export",
  deleteURL: "/crm/crmlinkrecord",
  deleteIsBatch: true,
  dataForm: {
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });


const addKey = ref(0);
const addOrUpdateRef = ref();
const addOrUpdateHandle = (lrdId?: number) => {
  addKey.value++;
  nextTick(() => {
    addOrUpdateRef.value.init(lrdId);
  });
};
</script>